package com.prs.crm.action.official;

import java.io.File;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.prs.crm.context.AppContext;
import com.prs.crm.context.Attach;
import com.prs.crm.context.FileUtil;
import com.prs.crm.context.ToolKits;
import com.prs.crm.domain.Attachment;
import com.prs.crm.domain.archives.ArchivesManager;
import com.prs.crm.domain.archives.ArchivesType;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.domain.official.FileTransmit;
import com.prs.crm.domain.official.FileTransmitCollect;
import com.prs.crm.domain.official.FileTransmitCollectType;
import com.prs.crm.domain.official.FileTransmitReceive;
import com.prs.crm.service.AttachmentService;
import com.prs.crm.service.archives.ArchivesManagerService;
import com.prs.crm.service.archives.ArchivesTypeService;
import com.prs.crm.service.hr.PersonService;
import com.prs.crm.service.official.FileTransmitCollectService;
import com.prs.crm.service.official.FileTransmitCollectTypeService;
import com.prs.crm.service.official.FileTransmitReceiveService;
import com.prs.crm.service.official.FileTransmitService;

public class FileTransmitAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private Integer[] ids;
	private PaginationSupport pagination;
	private File upload;
	private String uploadFileName;
	private PersonService personService;
	private String accepts;  //接收人id
	private String type;
	private FileTransmit fileTransmit;
	private FileTransmitService fileTransmitService;
	private FileTransmitReceive fileTransmitReceive;
	private FileTransmitReceiveService fileTransmitReceiveService;
	private FileTransmitCollect fileTransmitCollect;
	private FileTransmitCollectService fileTransmitCollectService;
	private FileTransmitCollectType fileTransmitCollectType;
	private FileTransmitCollectTypeService fileTransmitCollectTypeService;
	private ArchivesManager archivesManager;
	private ArchivesManagerService archivesManagerService;
	private ArchivesType archivesType;
	private ArchivesTypeService archivesTypeService;
	private Integer id;
	private Integer[] receiveIds;
	private List<Attach> attach;
	private AttachmentService attachmentService;
	public AttachmentService getAttachmentService() {
		return attachmentService;
	}
	public void setAttachmentService(AttachmentService attachmentService) {
		this.attachmentService = attachmentService;
	}
	public List<Attach> getAttach() {
		return attach;
	}
	public void setAttach(List<Attach> attach) {
		this.attach = attach;
	}
	public Integer[] getReceiveIds() {
		return receiveIds;
	}
	public void setReceiveIds(Integer[] receiveIds) {
		this.receiveIds = receiveIds;
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public ArchivesManager getArchivesManager() {
		return archivesManager;
	}
	public void setArchivesManager(ArchivesManager archivesManager) {
		this.archivesManager = archivesManager;
	}
	public ArchivesManagerService getArchivesManagerService() {
		return archivesManagerService;
	}
	public void setArchivesManagerService(
			ArchivesManagerService archivesManagerService) {
		this.archivesManagerService = archivesManagerService;
	}
	public ArchivesType getArchivesType() {
		return archivesType;
	}
	public void setArchivesType(ArchivesType archivesType) {
		this.archivesType = archivesType;
	}
	public ArchivesTypeService getArchivesTypeService() {
		return archivesTypeService;
	}
	public void setArchivesTypeService(ArchivesTypeService archivesTypeService) {
		this.archivesTypeService = archivesTypeService;
	}
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public File getUpload() {
		return upload;
	}
	public void setUpload(File upload) {
		this.upload = upload;
	}
	public String getUploadFileName() {
		return uploadFileName;
	}
	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}
	public PersonService getPersonService() {
		return personService;
	}
	public void setPersonService(PersonService personService) {
		this.personService = personService;
	}
	public String getAccepts() {
		return accepts;
	}
	public void setAccepts(String accepts) {
		this.accepts = accepts;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public FileTransmit getFileTransmit() {
		return fileTransmit;
	}
	public void setFileTransmit(FileTransmit fileTransmit) {
		this.fileTransmit = fileTransmit;
	}
	public FileTransmitService getFileTransmitService() {
		return fileTransmitService;
	}
	public void setFileTransmitService(FileTransmitService fileTransmitService) {
		this.fileTransmitService = fileTransmitService;
	}
	public FileTransmitReceive getFileTransmitReceive() {
		return fileTransmitReceive;
	}
	public void setFileTransmitReceive(FileTransmitReceive fileTransmitReceive) {
		this.fileTransmitReceive = fileTransmitReceive;
	}
	public FileTransmitReceiveService getFileTransmitReceiveService() {
		return fileTransmitReceiveService;
	}
	public void setFileTransmitReceiveService(
			FileTransmitReceiveService fileTransmitReceiveService) {
		this.fileTransmitReceiveService = fileTransmitReceiveService;
	}
	public FileTransmitCollect getFileTransmitCollect() {
		return fileTransmitCollect;
	}
	public void setFileTransmitCollect(FileTransmitCollect fileTransmitCollect) {
		this.fileTransmitCollect = fileTransmitCollect;
	}
	public FileTransmitCollectService getFileTransmitCollectService() {
		return fileTransmitCollectService;
	}
	public void setFileTransmitCollectService(
			FileTransmitCollectService fileTransmitCollectService) {
		this.fileTransmitCollectService = fileTransmitCollectService;
	}
	public FileTransmitCollectType getFileTransmitCollectType() {
		return fileTransmitCollectType;
	}
	public void setFileTransmitCollectType(
			FileTransmitCollectType fileTransmitCollectType) {
		this.fileTransmitCollectType = fileTransmitCollectType;
	}
	public FileTransmitCollectTypeService getFileTransmitCollectTypeService() {
		return fileTransmitCollectTypeService;
	}
	public void setFileTransmitCollectTypeService(
			FileTransmitCollectTypeService fileTransmitCollectTypeService) {
		this.fileTransmitCollectTypeService = fileTransmitCollectTypeService;
	}
	@Action("listSendFileTransmit")
	public String listSendFileTransmit(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(FileTransmit.class);
		criteria.add(Restrictions.eq("oabox", 1)).add(Restrictions.eq("recorder.id",  AppContext.getAccountContext().getUser().getId()));
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getFileTransmitService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	@Action("listReceiveFileTransmit")
	public String listReceiveFileTransmit(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(FileTransmitReceive.class);
		criteria.add(Restrictions.eq("oabox", 1)).add(Restrictions.eq("receivePerson.id", AppContext.getAccountContext().getUser().getId()));	
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getFileTransmitReceiveService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	@Action("listDraftFileTransmit")
	public String listDraftFileTransmit(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(FileTransmit.class);
		criteria.add(Restrictions.eq("oabox", 0)).add(Restrictions.eq("recorder.id",AppContext.getAccountContext().getUser().getId()));
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getFileTransmitService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	@Action("viewFileTransmit")
	public String viewFileTransmit(){
		return SUCCESS;
	}
	@Action("editFileTransmit")
	public String editFileTransmit(){
		if(ids!=null){
			this.fileTransmit=this.getFileTransmitService().get(ids[0]);
		}
		return SUCCESS;
	}
	@Action("editDraftFileTransmit")
	public String editDraftFileTransmit(){
		if(ids!=null){
			this.fileTransmit=this.getFileTransmitService().get(ids[0]);
		}
		return SUCCESS;
	}
	
	@Action(value = "sendFileTransmit", results = {
			@Result(name = "success", type = "redirect", location = "editFileTransmit"),
			@Result(name = "error", type = "chain", location = "editFileTransmit") })
	public String sendFileTransmit(){
		if (upload!=null) {
			Attachment attach=FileUtil.getInstance().createAttach(upload, uploadFileName);
			this.getAttachmentService().save(attach);
			fileTransmit.setAttach(attach);
		}else{
			this.addActionError("请上传文件！");
			return ERROR;
		}
		fileTransmit.setOabox(1);
		fileTransmit.setTop(0);
		fileTransmit.setCreatTime(new Date());
		fileTransmit.setAccepts(accepts);
		this.getFileTransmitService().save(fileTransmit);
		System.out.println(fileTransmit.getContent());
		//已收新闻
		Collection<Person> acceptPerson=this.getPersonService().findPersons(ToolKits.convertStringAryToIntAry(fileTransmit.getAccepts().split(",")));
		Iterator<Person> iter=acceptPerson.iterator();
		while (iter.hasNext()) {
			Person person =iter.next();
			FileTransmitReceive re=new FileTransmitReceive();
			re.setFileTransmitId(fileTransmit.getId());
			re.setContent(fileTransmit.getContent());
			re.setTitle(fileTransmit.getTitle());
			re.setDegree(fileTransmit.getDegree());
			if (fileTransmit.getAttach()!=null) {
				re.setAttach(fileTransmit.getAttach());
			}
			re.setOabox(1);
			re.setSendPerson(AppContext.getAccountContext().currentUser());
			re.setReceivePerson(person);
			re.setState("未读");
			this.getFileTransmitReceiveService().save(re);
		}
		return SUCCESS;
	}
	@Action(value = "sendFileTransmits", results = {
			@Result(name = "success", type = "redirect", location = "editFileTransmit"),
			@Result(name = "error", type = "chain", location = "editFileTransmit") })
	public String sendFileTransmits(){
		if (upload!=null) {
			Attachment attach=FileUtil.getInstance().createAttach(upload, uploadFileName);
			this.getAttachmentService().save(attach);
			fileTransmit.setAttach(attach);
		}
		fileTransmit.setOabox(1);
		fileTransmit.setTop(0);
		fileTransmit.setCreatTime(new Date());
		fileTransmit.setAccepts(accepts);
		this.getFileTransmitService().save(fileTransmit);
		System.out.println(fileTransmit.getContent());
		//已收新闻
		Collection<Person> acceptPerson=this.getPersonService().findPersons(ToolKits.convertStringAryToIntAry(fileTransmit.getAccepts().split(",")));
		Iterator<Person> iter=acceptPerson.iterator();
		while (iter.hasNext()) {
			Person person =iter.next();
			FileTransmitReceive re=new FileTransmitReceive();
			re.setFileTransmitId(fileTransmit.getId());
			re.setContent(fileTransmit.getContent());
			re.setTitle(fileTransmit.getTitle());
			re.setDegree(fileTransmit.getDegree());
			if (fileTransmit.getAttach()!=null) {
				re.setAttach(fileTransmit.getAttach());
			}
			re.setOabox(1);
			re.setSendPerson(AppContext.getAccountContext().currentUser());
			re.setReceivePerson(person);
			re.setState("未读");
			this.getFileTransmitReceiveService().save(re);
		}
		return SUCCESS;
	}
	@Action(value = "sendFileTransmits1", results = {
			@Result(name = "success", type = "redirect", location = "listReceiveFileTransmit"),
			@Result(name = "error", type = "chain", location = "listReceiveFileTransmit") })
	public String sendFileTransmits1(){
		if (upload!=null) {
			Attachment attach=FileUtil.getInstance().createAttach(upload, uploadFileName);
			this.getAttachmentService().save(attach);
			fileTransmit.setAttach(attach);
		}
		fileTransmit.setOabox(1);
		fileTransmit.setTop(0);
		fileTransmit.setCreatTime(new Date());
		fileTransmit.setAccepts(accepts);
		this.getFileTransmitService().save(fileTransmit);
		System.out.println(fileTransmit.getContent());
		//已收新闻
		Collection<Person> acceptPerson=this.getPersonService().findPersons(ToolKits.convertStringAryToIntAry(fileTransmit.getAccepts().split(",")));
		Iterator<Person> iter=acceptPerson.iterator();
		while (iter.hasNext()) {
			Person person =iter.next();
			FileTransmitReceive re=new FileTransmitReceive();
			re.setFileTransmitId(fileTransmit.getId());
			re.setContent(fileTransmit.getContent());
			re.setTitle(fileTransmit.getTitle());
			re.setDegree(fileTransmit.getDegree());
			if (fileTransmit.getAttach()!=null) {
				re.setAttach(fileTransmit.getAttach());
			}
			re.setOabox(1);
			re.setSendPerson(AppContext.getAccountContext().currentUser());
			re.setReceivePerson(person);
			re.setState("未读");
			this.getFileTransmitReceiveService().save(re);
		}
		return SUCCESS;
	}
	@Action(value = "sendDraftFileTransmit", results = {
			@Result(name = "success", type = "redirect", location = "listDraftFileTransmit"),
			@Result(name = "error", type = "chain", location = "editDraftFileTransmit") })
	public String sendDraftFileTransmit(){
		if (upload!=null) {
			Attachment attach=FileUtil.getInstance().createAttach(upload, uploadFileName);
			this.getAttachmentService().save(attach);
			fileTransmit.setAttach(attach);
		}
//		else{
//			this.addActionError("请上传文件！");
//			return ERROR;
//		}
		fileTransmit.setOabox(1);
		fileTransmit.setTop(0);
		fileTransmit.setCreatTime(new Date());
		fileTransmit.setAccepts(accepts);
		this.getFileTransmitService().save(fileTransmit);
		//已收新闻
		System.out.println(fileTransmit.getAccepts());
		Collection<Person> acceptPerson=this.getPersonService().findPersons(ToolKits.convertStringAryToIntAry(fileTransmit.getAccepts().split(",")));
		Iterator<Person> iter=acceptPerson.iterator();
		while (iter.hasNext()) {
			Person person =iter.next();
			FileTransmitReceive re=new FileTransmitReceive();
			re.setFileTransmitId(fileTransmit.getId());
			re.setContent(fileTransmit.getContent());
			re.setTitle(fileTransmit.getTitle());
			re.setDegree(fileTransmit.getDegree());
			if (fileTransmit.getAttach()!=null) {
				re.setAttach(fileTransmit.getAttach());
			}
			re.setOabox(1);
			re.setSendPerson(AppContext.getAccountContext().currentUser());
			re.setReceivePerson(person);
			re.setState("未读");
			this.getFileTransmitReceiveService().save(re);
		}
		return SUCCESS;
	}
	@Action(value = "sendDraftFileTransmits", results = {
			@Result(name = "success", type = "redirect", location = "listDraftFileTransmit"),
			@Result(name = "error", type = "chain", location = "listDraftFileTransmit") })
	public String sendDraftFileTransmits(){
		if (ids!=null) {
			this.fileTransmit=this.getFileTransmitService().get(ids[0]);
		}
		fileTransmit.setOabox(1);
		fileTransmit.setTop(0);
		fileTransmit.setCreatTime(new Date());
		this.getFileTransmitService().submit(fileTransmit);
		//已收新闻
		Collection<Person> acceptPerson=this.getPersonService().findPersons(ToolKits.convertStringAryToIntAry(fileTransmit.getAccepts().split(",")));
		Iterator<Person> iter=acceptPerson.iterator();
		while (iter.hasNext()) {
			Person person =iter.next();
			FileTransmitReceive re=new FileTransmitReceive();
			re.setFileTransmitId(fileTransmit.getId());
			re.setContent(fileTransmit.getContent());
			re.setTitle(fileTransmit.getTitle());
			re.setDegree(fileTransmit.getDegree());
			if (fileTransmit.getAttach()!=null) {
				re.setAttach(fileTransmit.getAttach());
			}
			re.setOabox(1);
			re.setSendPerson(AppContext.getAccountContext().currentUser());
			re.setReceivePerson(person);
			re.setState("未读");
			this.getFileTransmitReceiveService().save(re);
		}
		return SUCCESS;
	}
	@Action(value = "saveDraftFileTransmit", results = {
			@Result(name = "success", type = "redirect", location = "editFileTransmit"),
			@Result(name = "error", type = "chain", location = "editFileTransmit") })
	public String saveDraftFileTransmit(){
		if (upload!=null) {
			Attachment attach=FileUtil.getInstance().createAttach(upload, uploadFileName);
			this.getAttachmentService().save(attach);
			fileTransmit.setAttach(attach);
		}else{
			this.addActionError("请上传文件");
			return ERROR;
		}
		if (fileTransmit.getId()==null) {
			fileTransmit.setOabox(0);
			fileTransmit.setAccepts(accepts);
			this.getFileTransmitService().save(fileTransmit);
		}else{
			this.getFileTransmitService().submit(fileTransmit);
		}
		
		return SUCCESS;
	}
	@Action(value = "saveDraftFileTransmits", results = {
			@Result(name = "success", type = "redirect", location = "listDraftFileTransmit"),
			@Result(name = "error", type = "chain", location = "editDraftFileTransmit") })
	public String saveDraftFileTransmits(){
		if (upload!=null) {
			Attachment attach=FileUtil.getInstance().createAttach(upload, uploadFileName);
			this.getAttachmentService().save(attach);
			fileTransmit.setAttach(attach);
		}else{
			this.addActionError("请上传文件");
			return ERROR;
		}
		if (fileTransmit.getId()==null) {
			fileTransmit.setOabox(0);
			fileTransmit.setAccepts(accepts);
			this.getFileTransmitService().save(fileTransmit);
		}else{
			this.getFileTransmitService().submit(fileTransmit);
		}
		return SUCCESS;
	}
	@Action("viewFileTransmitReceive")
	public String viewFileTransmitReceive() {
		if(this.ids!=null){
			this.fileTransmitReceive=this.getFileTransmitReceiveService().get(ids[0]);
		}
		if(fileTransmitReceive.getState().equals("未读")){
			fileTransmitReceive.setState("已读");
			this.getFileTransmitReceiveService().submit(fileTransmitReceive);
		}
		return SUCCESS;
	}
	@Action("editForwardFileTransmit")
	public String editForwardFileTransmit(){
		if (fileTransmit!=null) {
			fileTransmit.setContent("<BR><BR>----- Original Message ----- <BR>"+
				"Form:"+fileTransmit.getRecorder().getResume().getName()+"<BR>"+
				"To:"+fileTransmit.getReceive()+"<BR>"+
				"Title:"+fileTransmit.getTitle()+"<BR>"+
				"Content:"+"<BR>"+
				fileTransmit.getContent());
			fileTransmit.setTitle("FW:"+fileTransmit.getTitle());
		}
		if (fileTransmitReceive!=null) {
			fileTransmit=new FileTransmit();
			fileTransmit.setContent("<BR><BR>----- Original Message ----- <BR>"+
					"Form:"+fileTransmitReceive.getRecorder().getResume().getName()+"<BR>"+
					"To:"+fileTransmitReceive.getReceivePerson().getResume().getName()+"<BR>"+
					"Title:"+fileTransmitReceive.getTitle()+"<BR>"+
					"Content:"+"<BR>"+
					fileTransmitReceive.getContent());
			fileTransmit.setTitle("FW:"+fileTransmitReceive.getTitle());
			if (fileTransmitReceive.getAttach()!=null) {
				fileTransmit.setAttach(fileTransmitReceive.getAttach());
				fileTransmit.getAttach().setId(fileTransmitReceive.getAttach().getId());
			}
		}
		if (ids!=null) {
			this.fileTransmit=this.getFileTransmitService().get(ids[0]);
			fileTransmit.setContent("<BR><BR>----- Original Message ----- <BR>"+
				"Form:"+fileTransmit.getRecorder().getResume().getName()+"<BR>"+
				"To:"+fileTransmit.getReceive()+"<BR>"+
				"Title:"+fileTransmit.getTitle()+"<BR>"+
				"Content:"+"<BR>"+
				fileTransmit.getContent());
			fileTransmit.setTitle("FW:"+fileTransmit.getTitle());
		}
		if (receiveIds!=null) {
			this.fileTransmitReceive=this.getFileTransmitReceiveService().get(receiveIds[0]);
			fileTransmit=new FileTransmit();
			fileTransmit.setContent("<BR><BR>----- Original Message ----- <BR>"+
					"Form:"+fileTransmitReceive.getRecorder().getResume().getName()+"<BR>"+
					"To:"+fileTransmitReceive.getReceivePerson().getResume().getName()+"<BR>"+
					"Title:"+fileTransmitReceive.getTitle()+"<BR>"+
					"Content:"+"<BR>"+
					fileTransmitReceive.getContent());
			fileTransmit.setTitle("FW:"+fileTransmitReceive.getTitle());
			if (fileTransmitReceive.getAttach()!=null) {
				fileTransmit.setAttach(fileTransmitReceive.getAttach());
			}
		}
		return SUCCESS;
	}
	@Action("editReplyFileTransmit")
	public String editReplyFileTransmit(){
		if (ids!=null) {
			this.fileTransmitReceive=this.getFileTransmitReceiveService().get(ids[0]);
//			this.fileTransmit=this.fileTransmitReceive.getFileTransmit();
		}
		FileTransmit ft=this.getFileTransmitService().getFileTransmitById(fileTransmitReceive.getFileTransmitId());
		if (ft!=null) {
			if (type.equals("1")) {
				fileTransmit=new FileTransmit();
				fileTransmit.setContent("<BR><BR>----- Original Message ----- <BR>"+
						"Form:"+ft.getRecorder().getResume().getName()+"<BR>"+
						"To:"+ft.getReceive()+"<BR>"+
						"Title:"+ft.getTitle()+"<BR>"+
						"Content:"+"<BR>"+
						ft.getContent());
					this.accepts=ft.getAccepts();
					fileTransmit.setTitle("Fe:"+ft.getTitle());
			}else{
				fileTransmit=new FileTransmit();
				String[] receive=ft.getReceive().split(",");
				String[] acc=ft.getAccepts().split(",");
				fileTransmit.setContent("<BR><BR>----- Original Message ----- <BR>"+
						"Form:"+ft.getRecorder().getResume().getName()+"<BR>"+
						"To:"+receive[0]+"<BR>"+
						"Title:"+ft.getTitle()+"<BR>"+
						"Content:"+"<BR>"+
						ft.getContent());
				this.accepts=acc[0];
				fileTransmit.setTitle("Fe:"+ft.getTitle());
			}
		}
		return SUCCESS;
	}
	@Action(value = "saveSendFileTransmitCollect", results = {
			@Result(name = "success", type = "redirect", location = "listSendFileTransmit"),
			@Result(name = "error", type = "chain", location = "viewFileTransmit?fileTransmit=${fileTransmit.getId()}") })
	public String saveSendFileTransmitCollect(){
		if (fileTransmit!=null) {
			fileTransmitCollect=new FileTransmitCollect();
			fileTransmitCollect.setFileTransmit(fileTransmit);
			FileTransmitCollectType fc=this.getFileTransmitCollectTypeService().getFileTransmitCollectType("已发信息");
			if (fc==null) {
				fc=new FileTransmitCollectType();
				fc.setName("已发信息");
				this.getFileTransmitCollectTypeService().save(fc);
			}
			fileTransmitCollect.setType(fc);
			this.getFileTransmitCollectService().save(fileTransmitCollect);
			fileTransmit.setOabox(2);
			this.getFileTransmitService().submit(fileTransmit);
		}
		return SUCCESS;
	}
	@Action(value = "saveReceiveFileTransmitCollect", results = {
			@Result(name = "success", type = "redirect", location = "listReceiveFileTransmit"),
			@Result(name = "error", type = "chain", location = "viewFileTransmitReceive?fileTransmitReceive=${fileTransmitReceive.getId()}") })
	public String saveReceiveFileTransmitCollect(){
		if (fileTransmitReceive!=null) {
			fileTransmitReceive.setOabox(2);
			this.getFileTransmitReceiveService().submit(fileTransmitReceive);
			FileTransmitCollect collect=new FileTransmitCollect();
			collect.setFileTransmitReceive(fileTransmitReceive);
			FileTransmitCollectType fc=this.getFileTransmitCollectTypeService().getFileTransmitCollectType("已收信息");
			if(fc==null){
				fc=new FileTransmitCollectType();
				fc.setName("已收信息");
				this.getFileTransmitCollectTypeService().save(fc);
			}
			collect.setType(fc);
			this.getFileTransmitCollectService().save(collect);
			
		}
		return SUCCESS;
	}
	
	@Action("listFileTransmitCollect")
	public String listFileTransmitCollect(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(FileTransmitCollect.class)
		.add(Restrictions.eq("recorder.id",AppContext.getAccountContext().getUser().getId()));
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getFileTransmitCollectService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	@Action("listFileTransmitCollectType")
	public String listFileTransmitCollectType(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(FileTransmitCollectType.class);
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getFileTransmitCollectTypeService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	@Action("editFileTransmitCollectType")
	public String editFileTransmitCollectType(){
		if(ids!=null){
			this.fileTransmitCollectType=this.getFileTransmitCollectTypeService().get(ids[0]);
		}
		return SUCCESS;
	}
	@Action(value = "saveFileTransmitCollectType", results = {
			@Result(name = "success", type = "redirect", location = "listFileTransmitCollectType"),
			@Result(name = "error", type = "chain", location = "editFileTransmitCollectType") })
	public String saveFileTransmitCollectType(){
		this.getFileTransmitCollectTypeService().save(fileTransmitCollectType);
		return SUCCESS;
	}
	
	
	@Action(value = "removeFileTransmitCollectType", results = {
			@Result(name = "success", type = "redirect", location = "listFileTransmitCollectType"),
			@Result(name = "error", type = "chain", location = "listFileTransmitCollectType") })
	public String removeFileTransmitCollectType(){
		if (ids!=null) {
			this.fileTransmitCollectType=this.getFileTransmitCollectTypeService().get(ids[0]);
			if(fileTransmitCollectType.getFileTransmitCollect().size()!=0){
				this.addActionError("指定类别为系统内置类别，不能进行操作。");
				return ERROR;
			}
		}
		this.getFileTransmitCollectTypeService().batchRemove(ids);
		return SUCCESS;
	}
	@Action(value = "removeSendFileTransmit", results = {
			@Result(name = "success", type = "redirect", location = "listSendFileTransmit"),
			@Result(name = "error", type = "chain", location = "listSendFileTransmit") })
	public String removeSendFileTransmit(){
		if (ids!=null) {
			this.fileTransmit=this.getFileTransmitService().get(ids[0]);
			if (fileTransmit.getFileTransmitCollect().size()!=0) {
				this.addActionError("信息已收藏，不能删除！");
				return ERROR;
			}
		}
		this.getFileTransmitService().batchRemove(ids);
		return SUCCESS;
	}
	@Action(value = "removeForwardShortMessage", results = {
			@Result(name = "success", type = "redirect", location = "listDraftFileTransmit"),
			@Result(name = "error", type = "chain", location = "listDraftFileTransmit") })
	public String removeForwardShortMessage(){
		if (ids!=null) {
			this.fileTransmit=this.getFileTransmitService().get(ids[0]);
		}
		this.getFileTransmitService().batchRemove(ids);
		return SUCCESS;
	}
	@Action(value = "removeSendFileTransmits", results = {
			@Result(name = "success", type = "redirect", location = "listSendFileTransmit"),
			@Result(name = "error", type = "chain", location = "viewFileTransmit") })
	public String removeSendFileTransmits(){
		if (fileTransmit.getFileTransmitCollect().size()!=0) {
			this.addActionError("信息已收藏，不能删除！");
			return ERROR;
		}
		this.getFileTransmitService().remove(fileTransmit);
		return SUCCESS;
	}
	@Action(value = "removeReceiveFileTransmit", results = {
			@Result(name = "success", type = "redirect", location = "listReceiveFileTransmit"),
			@Result(name = "error", type = "chain", location = "listReceiveFileTransmit") })
	public String removeReceiveFileTransmit(){
		if (ids!=null) {
			this.fileTransmitReceive=this.getFileTransmitReceiveService().get(ids[0]);
		}
		this.getFileTransmitReceiveService().batchRemove(ids);
		return SUCCESS;
	}
	@Action(value = "removeReceiveFileTransmits", results = {
			@Result(name = "success", type = "redirect", location = "listReceiveFileTransmit"),
			@Result(name = "error", type = "chain", location = "viewFileTransmitReceive") })
	public String removeReceiveFileTransmits(){
		this.getFileTransmitReceiveService().remove(fileTransmitReceive);
		return SUCCESS;
	}
	@Action(value = "removeFileTransmitCollect", results = {
			@Result(name = "success", type = "redirect", location = "listFileTransmitCollect"),
			@Result(name = "error", type = "chain", location = "listFileTransmitCollect") })
	public String removeFileTransmitCollect(){
		if (ids!=null) {
			this.fileTransmitCollect=this.getFileTransmitCollectService().get(ids[0]);
		}
		this.getFileTransmitCollectService().batchRemove(ids);
		return SUCCESS;
	}
	
	@Action(value = "saveFileTransmitFile", results = {
			@Result(name = "success", type = "redirect", location = "listSendFileTransmit"),
			@Result(name = "error", type = "chain", location = "listSendFileTransmit") })
	public String saveFileTransmitFile(){
		if (ids!=null) {
			this.fileTransmit=this.getFileTransmitService().get(ids[0]);
		}
		this.archivesType=this.archivesTypeService.get(id);
		ArchivesManager am=new ArchivesManager();
		am.setArchivesType(archivesType);
		am.setNumber("MSG"+new Date().getTime()+"G");
		am.setArchivesName(fileTransmit.getTitle());
		am.setDegree(fileTransmit.getDegree());
		am.setSendTime(fileTransmit.getRecordTime());
		am.setSendPerson(fileTransmit.getRecorder());
		am.setReceivePerson(fileTransmit.getReceive());
		am.setContent(fileTransmit.getContent());
		am.setState(0);
		if (fileTransmit.getAttach()!=null) {
			am.setAttach(fileTransmit.getAttach());
		}
		am.setMark(1);
		this.getArchivesManagerService().save(am);
		fileTransmit.setOabox(4);//4为归档
		this.getFileTransmitService().submit(fileTransmit);
		return SUCCESS;
	}
	@Action(value = "saveFileTransmitReceiveFile", results = {
			@Result(name = "success", type = "redirect", location = "listReceiveFileTransmit"),
			@Result(name = "error", type = "chain", location = "listReceiveFileTransmit") })
	public String saveFileTransmitReceiveFile(){
		if (ids!=null) {
			this.fileTransmitReceive=this.getFileTransmitReceiveService().get(ids[0]);
		}
		this.archivesType=this.archivesTypeService.get(id);
		ArchivesManager am=new ArchivesManager();
		am.setArchivesType(archivesType);
		am.setNumber("MSG"+new Date().getTime()+"G");
		am.setArchivesName(fileTransmitReceive.getTitle());
		am.setDegree(fileTransmitReceive.getDegree());
		am.setSendTime(fileTransmitReceive.getRecordTime());
		am.setSendPerson(fileTransmitReceive.getRecorder());
		am.setReceivePerson(fileTransmitReceive.getReceivePerson().getResume().getName());
		am.setContent(fileTransmitReceive.getContent());
		am.setState(0);
		if (fileTransmitReceive.getAttach()!=null) {
			am.setAttach(fileTransmitReceive.getAttach());
		}
		am.setMark(1);
		this.getArchivesManagerService().save(am);
		fileTransmitReceive.setOabox(4);//4为归档
		this.getFileTransmitReceiveService().submit(fileTransmitReceive);
		return SUCCESS;
	}
	@Action(value = "saveFileTransmitCollectFile", results = {
			@Result(name = "success", type = "redirect", location = "listFileTransmitCollect"),
			@Result(name = "error", type = "chain", location = "listFileTransmitCollect") })
	public String saveFileTransmitCollectFile(){
		if (ids!=null) {
			this.fileTransmitCollect=this.getFileTransmitCollectService().get(ids[0]);
		}
		this.archivesType=this.archivesTypeService.get(id);
		ArchivesManager am=new ArchivesManager();
		am.setArchivesType(archivesType);
		am.setNumber("MSG"+new Date().getTime()+"G");
		am.setArchivesName(fileTransmitCollect.getFileTransmit().getTitle());
		am.setDegree(fileTransmitCollect.getFileTransmit().getDegree());
		am.setSendTime(fileTransmitCollect.getFileTransmit().getRecordTime());
		am.setSendPerson(fileTransmitCollect.getFileTransmit().getRecorder());
		am.setReceivePerson(fileTransmitCollect.getFileTransmit().getReceive());
		am.setContent(fileTransmitCollect.getFileTransmit().getContent());
		am.setState(0);
		if (fileTransmitCollect.getFileTransmit().getAttach()!=null) {
			am.setAttach(fileTransmitCollect.getFileTransmit().getAttach());
		}
		am.setMark(1);
		this.getArchivesManagerService().save(am);
		fileTransmitCollect.getFileTransmit().setOabox(4);//4为归档
		this.getFileTransmitCollectService().submit(fileTransmitCollect);
		return SUCCESS;
	}
}
